from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-10 14:02:06.015546
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 10, Apr, 2022
Time: 14:02:11
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.9047
Nobs: 622.000 HQIC: -49.2968
Log likelihood: 7555.63 FPE: 3.03667e-22
AIC: -49.5461 Det(Omega_mle): 2.63062e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.335684 0.063998 5.245 0.000
L1.Burgenland 0.105841 0.039975 2.648 0.008
L1.Kärnten -0.110501 0.020921 -5.282 0.000
L1.Niederösterreich 0.196195 0.083558 2.348 0.019
L1.Oberösterreich 0.118947 0.082284 1.446 0.148
L1.Salzburg 0.259780 0.042400 6.127 0.000
L1.Steiermark 0.042867 0.055839 0.768 0.443
L1.Tirol 0.104755 0.045145 2.320 0.020
L1.Vorarlberg -0.065643 0.039870 -1.646 0.100
L1.Wien 0.018582 0.073241 0.254 0.800
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048615 0.137120 0.355 0.723
L1.Burgenland -0.038043 0.085648 -0.444 0.657
L1.Kärnten 0.041990 0.044824 0.937 0.349
L1.Niederösterreich -0.201370 0.179029 -1.125 0.261
L1.Oberösterreich 0.454838 0.176299 2.580 0.010
L1.Salzburg 0.282482 0.090844 3.110 0.002
L1.Steiermark 0.112726 0.119638 0.942 0.346
L1.Tirol 0.305949 0.096727 3.163 0.002
L1.Vorarlberg 0.026613 0.085424 0.312 0.755
L1.Wien -0.025168 0.156923 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192522 0.032698 5.888 0.000
L1.Burgenland 0.088758 0.020424 4.346 0.000
L1.Kärnten -0.007214 0.010689 -0.675 0.500
L1.Niederösterreich 0.243933 0.042692 5.714 0.000
L1.Oberösterreich 0.160193 0.042041 3.810 0.000
L1.Salzburg 0.040046 0.021663 1.849 0.065
L1.Steiermark 0.028636 0.028529 1.004 0.315
L1.Tirol 0.082880 0.023066 3.593 0.000
L1.Vorarlberg 0.054712 0.020370 2.686 0.007
L1.Wien 0.117300 0.037420 3.135 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112201 0.032748 3.426 0.001
L1.Burgenland 0.042411 0.020455 2.073 0.038
L1.Kärnten -0.013160 0.010705 -1.229 0.219
L1.Niederösterreich 0.174118 0.042757 4.072 0.000
L1.Oberösterreich 0.333433 0.042105 7.919 0.000
L1.Salzburg 0.100154 0.021696 4.616 0.000
L1.Steiermark 0.113556 0.028573 3.974 0.000
L1.Tirol 0.091051 0.023101 3.941 0.000
L1.Vorarlberg 0.060805 0.020401 2.980 0.003
L1.Wien -0.015097 0.037477 -0.403 0.687
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114475 0.061277 1.868 0.062
L1.Burgenland -0.045774 0.038275 -1.196 0.232
L1.Kärnten -0.045403 0.020031 -2.267 0.023
L1.Niederösterreich 0.139202 0.080005 1.740 0.082
L1.Oberösterreich 0.162072 0.078786 2.057 0.040
L1.Salzburg 0.284864 0.040597 7.017 0.000
L1.Steiermark 0.061239 0.053465 1.145 0.252
L1.Tirol 0.159442 0.043226 3.689 0.000
L1.Vorarlberg 0.098307 0.038175 2.575 0.010
L1.Wien 0.074002 0.070126 1.055 0.291
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057188 0.047978 1.192 0.233
L1.Burgenland 0.025609 0.029968 0.855 0.393
L1.Kärnten 0.053062 0.015684 3.383 0.001
L1.Niederösterreich 0.194276 0.062641 3.101 0.002
L1.Oberösterreich 0.331795 0.061686 5.379 0.000
L1.Salzburg 0.035877 0.031786 1.129 0.259
L1.Steiermark 0.013113 0.041861 0.313 0.754
L1.Tirol 0.120687 0.033844 3.566 0.000
L1.Vorarlberg 0.067251 0.029889 2.250 0.024
L1.Wien 0.102146 0.054906 1.860 0.063
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170108 0.057710 2.948 0.003
L1.Burgenland 0.005366 0.036047 0.149 0.882
L1.Kärnten -0.065794 0.018865 -3.488 0.000
L1.Niederösterreich -0.104545 0.075348 -1.387 0.165
L1.Oberösterreich 0.206572 0.074199 2.784 0.005
L1.Salzburg 0.054157 0.038234 1.416 0.157
L1.Steiermark 0.247150 0.050352 4.908 0.000
L1.Tirol 0.501609 0.040709 12.322 0.000
L1.Vorarlberg 0.063718 0.035952 1.772 0.076
L1.Wien -0.075751 0.066044 -1.147 0.251
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153842 0.063999 2.404 0.016
L1.Burgenland -0.002454 0.039975 -0.061 0.951
L1.Kärnten 0.062576 0.020921 2.991 0.003
L1.Niederösterreich 0.170464 0.083559 2.040 0.041
L1.Oberösterreich -0.055741 0.082285 -0.677 0.498
L1.Salzburg 0.207715 0.042400 4.899 0.000
L1.Steiermark 0.139412 0.055839 2.497 0.013
L1.Tirol 0.058018 0.045146 1.285 0.199
L1.Vorarlberg 0.146954 0.039870 3.686 0.000
L1.Wien 0.121899 0.073241 1.664 0.096
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.382788 0.037711 10.151 0.000
L1.Burgenland -0.003694 0.023555 -0.157 0.875
L1.Kärnten -0.020841 0.012327 -1.691 0.091
L1.Niederösterreich 0.203196 0.049236 4.127 0.000
L1.Oberösterreich 0.230226 0.048486 4.748 0.000
L1.Salzburg 0.036733 0.024984 1.470 0.141
L1.Steiermark -0.012295 0.032903 -0.374 0.709
L1.Tirol 0.089524 0.026602 3.365 0.001
L1.Vorarlberg 0.052740 0.023493 2.245 0.025
L1.Wien 0.044272 0.043157 1.026 0.305
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036568 0.109961 0.172440 0.139657 0.102157 0.081078 0.036065 0.211379
Kärnten 0.036568 1.000000 -0.025698 0.131270 0.049409 0.085780 0.443695 -0.066074 0.089743
Niederösterreich 0.109961 -0.025698 1.000000 0.315211 0.122250 0.276183 0.068753 0.154971 0.294349
Oberösterreich 0.172440 0.131270 0.315211 1.000000 0.214180 0.298544 0.167092 0.138564 0.240843
Salzburg 0.139657 0.049409 0.122250 0.214180 1.000000 0.126167 0.093383 0.106247 0.126270
Steiermark 0.102157 0.085780 0.276183 0.298544 0.126167 1.000000 0.136076 0.110796 0.039360
Tirol 0.081078 0.443695 0.068753 0.167092 0.093383 0.136076 1.000000 0.065746 0.150554
Vorarlberg 0.036065 -0.066074 0.154971 0.138564 0.106247 0.110796 0.065746 1.000000 -0.003449
Wien 0.211379 0.089743 0.294349 0.240843 0.126270 0.039360 0.150554 -0.003449 1.000000